package com.example.netty.realNetty.primise;

import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.DefaultPromise;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.parallel.Execution;

import java.util.concurrent.ExecutionException;

@Slf4j
public class Promise {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        EventLoop eventLoop = new NioEventLoopGroup().next();
        DefaultPromise<Integer> promise = new DefaultPromise<>(eventLoop);
        new Thread(()->{
            log.debug("3秒后开始计算");
            try {
                int i = 1 / 0;
                Thread.sleep(3000);
                promise.setSuccess(80);
                log.debug("计算结果: {}",promise.get());
            } catch (Exception e) {
                promise.setFailure(e);
            }
        }).start();
        log.debug(promise.get() + "");
        log.debug("主线程结束");
    }
}
